package com.gao.controller;

import com.gao.mapper.UserMapper;
import com.gao.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Projectname springboot-05-mybatis
 * @Filename UserController
 * @Author an
 * @Data 2022/8/14 9:00
 * @Description TODO
 */
@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/queryuserlist")
    public List<User> queryUserList(){
        List<User> users = userMapper.queryUserList();
        return users;
    }
    @GetMapping("/adduser")
    public String addUser(){
        User user = new User(14, "小明", "12343", 20, "男", "123@qq.com");
        userMapper.addUser(user);
        return "update-ok";
    }

    @GetMapping("/updateuser/{id}")
    public String updateUser(@PathVariable("id") Integer id){
        User user = new User(id, "小明", "11111", 20, "男", "123@qq.com");
        userMapper.updateUser(user);

        return "updateuser";
    }

    @GetMapping("/deleteuser/{id}")
    public String deleteUser(@PathVariable("id") Integer id){
        userMapper.deleteUser(id);
        return "deleteuser";
    }

}
